package it.com.chen.malavolta.jingsen.entities;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import it.com.chen.malavolta.jingsen.entities.*;


/**
 * Session Bean implementation class BookManager
 */
@Stateless
public class BookManager implements BookManagerRemote {
	@PersistenceContext
	private EntityManager em;

    /**
     * Default constructor. 
     */
    public BookManager() {
        // TODO Auto-generated constructor stub
    }

	@Override
	public void add(String ISBN, String name, String author) {
		Book book = new Book();
		book.setBook_ISBN(ISBN);
		book.setName(name);
		book.setAuthor(author);
		em.flush();
		em.persist(book);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List getAllBookName() {
		List<String> list = null;
		try {
			list  = em.createQuery("SELECT b FROM Book b").getResultList();
		} catch (Exception e) {
			System.out.println("Execute Sql statement Error");
		}
		return list; 
	}

}
